//
// Created by xyx16 on 2025/8/4.
//
#include<iostream>
#include<vector>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using namespace std;

class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
       unordered_set<string> set;
       vector<vector<int>> res;

       for (int i = 0; i < nums.size(); i++)
       {
         unordered_map<int, int> map;
         int target=0-nums[i];
         for(int j=i+1; j<nums.size(); j++)
         {
           int needNum = target-nums[j];
           map[nums[j]]=j;
           if(map.find(needNum) != map.end())
           {
             vector<int> temp = {nums[i], nums[j], needNum};
             sort(temp.begin(), temp.end());
             string key=to_string(temp[0])+"_"+to_string(temp[1])+"_"+to_string(temp[2]);
             if(set.find(key) == set.end())
             {
               res.push_back(temp);
               set.insert(key);
             }
           }
         }
       }
       return res;
    }
};
int main()
{
  Solution s;
  vector<int> nums = {-1, 0, 1, 2, -1, -4};
  vector<vector<int> > result = s.threeSum(nums);
  for (vector<int> v : result)
  {
    for (int i : v)
    {
      cout << i << " ";
    }
    cout << endl;
  }
}
